package com.whfc.ms.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppExamPaperDTO;
import com.whfc.emp.param.*;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsExamPaperService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 考试管理
 *
 * @author realm
 * @Description:
 */
@RestController
@RequestMapping("/ms/api/examPaper")
public class AppExamPaperController extends BaseController {
    @Autowired
    private MsExamPaperService msExamPaperService;

    /**
     * 试卷列表
     *
     * @param user
     * @param request
     * @param startDate
     * @param endDate
     * @return
     */
    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated AppExamPaperListParam request,
                       @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                       @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        request.setStartTime(startDate);
        request.setEndTime(endDate);
        PageData<AppExamPaperDTO> pageData = msExamPaperService.list(request);
        return ResultUtil.success(pageData);
    }

    /**
     * 考试管理- 新增
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/examPaper/add")
    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppExamPaperAddParam request) {
        msExamPaperService.add(request);
        return ResultUtil.success();
    }


    /**
     * 考试管理-编辑
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/examPaper/edit")
    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppExamPaperEditParam request) {
        logger.info("考试管理-编辑，loginer:{},AppTrainEditParam:{}", user.getUsername(), request.toString());
        msExamPaperService.edit(request);
        return ResultUtil.success();
    }


    /**
     * 考试管理-删除
     *
     * @param user
     * @param id
     * @return
     */
    @RequiresPermissions("emp/examPaper/del")
    @PostMapping("/del/{id}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @PathVariable("id") Integer id) {
        msExamPaperService.del(id);
        return ResultUtil.success();

    }



}
